<?php

namespace app\forms\position;

use app\forms\Model;
use app\models\Group;
use app\models\Department;
use app\validators\PositiveInteger;

/**
 * 岗位 父类表单
 */
class BaseForm extends Model
{
    public $groupId;
    public $deptId;
    public $parentId;
    public $name;

    public $item;
    public $auth;
    public $data;

    public function rules()
    {
        return [
            ['groupId', PositiveInteger::class],
            ['groupId', 'required', 'message' => '组织不能为空'],
            ['groupId', 'exist', 'targetClass' => Group::class, 'targetAttribute' => 'id'],

            ['deptId', PositiveInteger::class],
            ['deptId', 'required', 'message' => '部门不能为空'],
            ['deptId', 'exist', 'targetClass' => Department::class, 'targetAttribute' => 'id'],

            ['parentId', 'integer'],
            ['parentId', 'default', 'value' => 0],

            ['name', 'trim'],
            ['name', 'string', 'max' => 32],
            ['name', 'required', 'message' => '名称不能为空'],

            ['item', 'safe'],

            ['auth', 'safe'],
        ];
    }
}